<?php
/**
 * @filename GumballMachine.php
 * @author LD King
 * @encoding UTF-8
 * @date 2008-9-13 | 下午07:57:17
 * @package 
 * @subpackage 
 * @usage 
 * @note 糖果机
 * @copyright Copyright (c) 2007 - 2008 LD (http://mifunny.info)
 * @version $Id: $
 */

include_once 'State.php';

/**
 * 糖果机
 *
 */
class GumballMachine {
	
	public $soldoutState;
	public $noQuarterState;
	public $hasQuarterState;
	public $soldState;
	
	/**
	 * 状态
	 *
	 * @var State
	 */
	public static $state;
	
	/**
	 * 计数
	 *
	 * @var int
	 */
	public static $count;
	
	/**
	 * 初始化
	 *
	 * @param int $numberGumballs
	 */
	public function __construct($numberGumballs) {
		$this->noQuarterState = new NoQuarterState($this);
		
		self::$count = $numberGumballs;
		if ($numberGumballs > 0) {
			self::$state = $this->noQuarterState; 
		}
	} /* END func __construct */
	
	public function setState(State $state) {
		self::$state = $state;
	}

	public function insertQuarter() {
		self::$state->insertQuarter();
	}
	
	public function ejectQuarter() {
		self::$state->ejectQuarter();
	}
	
	public function turnCrank() {
		self::$state->turnCrank();
		self::$state->dispense();
	}
	
	public function releaseBall() {
		echo "有糖果出来了，别让它丢了！";
		self::$count -= 1;
	}
	
	/**
	 * getter方法.... 略
	 *
	 */
	public function getHasQuarterState() {
		
	}
}
?>